#define _CRT_SECURE_NO_WARNINGS 1

#include"ObjectPool.h"
#include"courrentAlloc.h"
void  Allcoate1()
{
	for (int i = 0; i < 1024; i++)
	{
		void* ptr = concurrentAlloc(6);
		cout << std::this_thread::get_id() << ":" ;
		printf("%X\n", pthreadpool);

	}
}


void Allcoate2()
{
	for (int i = 0; i < 1024; i++)
	{
		void* ptr = concurrentAlloc(8);
		cout << std::this_thread::get_id() << ":" << pthreadpool << ":";
		printf("%X\n", pthreadpool);

	}
}
void TestObjectPool1()
{
	std::thread x1(Allcoate1);
	x1.join();

	std::thread x2(Allcoate2);
	x2.join();

}

void TestCourrentallcoate1()
{
	void* p1 = concurrentAlloc(1);
	cout << p1 << endl;
	void* p2 = concurrentAlloc(7);
	cout << p2 << endl;

	void* p3 = concurrentAlloc(12);
	cout << p3 << endl;

	void* p4 = concurrentAlloc(20);

	cout << p4 << endl;

	concurrentfree(p1, 1);
	concurrentfree(p2, 7);
	concurrentfree(p3, 12);
	concurrentfree(p4, 20);
}
void test2()
{

	void* p1 = concurrentAlloc(6);
	void* p2 = concurrentAlloc(8);
	void* p3 = concurrentAlloc(1);
	void* p4 = concurrentAlloc(7);
	void* p5 = concurrentAlloc(8);

	cout << p1 << endl;
	cout << p2 << endl; 
	cout << p3<< endl; 
	cout << p4 << endl; 
	cout << p5 << endl;
	concurrentfree(p1, 6);
	concurrentfree(p2, 8);
	concurrentfree(p3, 1);
	concurrentfree(p4, 7);
	concurrentfree(p5, 8);
}
void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = concurrentAlloc(6);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		concurrentfree(e, 6);
	}
}

void MultiThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = concurrentAlloc(16);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		concurrentfree(e, 16);
	}
}

void TestMultiThread()
{
	std::thread t1(MultiThreadAlloc1);
	std::thread t2(MultiThreadAlloc2);

	t1.join();
	t2.join();
}
void test3()
{
	void* p1 = concurrentAlloc(257*1024);
	concurrentfree(p1, 257*1024);
	void* p2 = concurrentAlloc(129*8*1024);
	concurrentfree(p2, 129 * 8 * 1024);

}
//void BigAlloc()
//{
//	void* p1 = concurrentAlloc(257 * 1024);
//	concurrentfree(p1);
//
//	void* p2 = concurrentAlloc(129 * 8 * 1024);
//	concurrentfree(p2);
//}

int main()
{
	//TestObjectPool1();
	//TestCourrentallcoate1();
	//test2();
	//TestMultiThread();
	test3();
	return 0;
}